/*
 * Copyright 2010 J Patrick Davenport
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package v4view.web;

import static org.junit.Assert.assertEquals;

import java.util.ArrayList;
import java.util.List;

import org.junit.Test;

import v4view.web.ext.BindingSelect;

/**
 * Provides a means by which to test all implementations of the ILanguage interface.
 * @author J Patrick Davenport
 *
 */
public class LanguageAttributesTests {
	@SuppressWarnings("rawtypes")
	private List<ILanguageAttributes>	langs;
	@SuppressWarnings("rawtypes")
	private ILanguageAttributes			lang;

	@SuppressWarnings("rawtypes")
	public LanguageAttributesTests() {
		this.langs = new ArrayList<ILanguageAttributes>();
		this.langs.add(new A());
		this.langs.add(new Body());
		this.langs.add(new Form());
		this.langs.add(new Head());
		this.langs.add(new Html());
		this.langs.add(new Image());
		this.langs.add(new Image());
		this.langs.add(new Li());
		this.langs.add(new Link());
		this.langs.add(new OptGroup());
		this.langs.add(new Option());
		this.langs.add(new Select());
		this.langs.add(new Ul());
		this.langs.add(new Caption());
		this.langs.add(new Div());
		this.langs.add(new P());
		this.langs.add(new Span());
		this.langs.add(new Table());
		this.langs.add(new Tr());
		this.langs.add(new TBody());
		this.langs.add(new TFoot());
		this.langs.add(new THead());
		this.langs.add(new Td());
		this.langs.add(new CheckBox());
		this.langs.add(new File());
		this.langs.add(new Hidden());
		this.langs.add(new InputButton());
		this.langs.add(new InputImage());
		this.langs.add(new Reset());
		this.langs.add(new Submit());
		this.langs.add(new Text());
		this.langs.add(new BindingSelect());
		this.langs.add(new HtmlObject());
	}

	@SuppressWarnings("rawtypes")
	@Test
	public void runTests() throws Exception {
		for (final ILanguageAttributes l : this.langs) {
			try {
				this.lang = l;
				this.checkGetSetDir();
				this.checkGetSetLang();
				this.checkGetSetXmlLang();
			} catch (final Exception ex) {
				System.err.println("Class failed lang: " + this.lang.getClass());
				throw ex;
			}
		}
	}

	public void checkGetSetXmlLang() {
		final String xmlLang = "i don't know what goes in this in real life.";
		final PageElement setXmlLang = this.lang.setXmlLang(xmlLang);
		assertEquals(this.lang, setXmlLang);
		assertEquals(xmlLang, this.lang.getXmlLang());

		final String xmlLang2 = "I've never used this";
		final PageElement setXmlLang2 = this.lang.setXmlLang(xmlLang2);
		assertEquals(this.lang, setXmlLang2);
		assertEquals(xmlLang2, this.lang.getXmlLang());
	}

	public void checkGetSetLang() {
		final String language = "en";
		final PageElement setLang = this.lang.setLang(language);
		assertEquals(this.lang, setLang);
		assertEquals(language, this.lang.getLang());

		final String lang2 = "fr";
		final PageElement setLang2 = this.lang.setLang(lang2);
		assertEquals(this.lang, setLang2);
		assertEquals(this.lang.getLang(), lang2);
	}

	public void checkGetSetDir() {
		final String dir1 = "huh";
		final PageElement setDir = this.lang.setDir(dir1);
		assertEquals(dir1, this.lang.getDir());
		assertEquals(setDir, this.lang);

		final String dir2 = "moo";
		final PageElement setDirAgain = this.lang.setDir(dir2);
		assertEquals(dir2, this.lang.getDir());
		assertEquals(setDirAgain, this.lang);
	}
}
